package com.uchiha.nova.mainService.controller;

import com.google.common.collect.Lists;
import com.uchiha.nova.core.feign.TenantUserFeignService;
import com.uchiha.nova.core.model.dto.TenantUserDTO;
import com.uchiha.nova.core.model.query.TenantUserQuery;
import com.uchiha.nova.core.tool.api.R;
import com.uchiha.nova.core.tool.constant.NovaCRUDMethodConstant;
import com.uchiha.nova.core.tool.support.BaseController;
import com.uchiha.nova.core.tool.support.NovaUser;
import com.uchiha.nova.core.tool.support.QueryContext;
import com.uchiha.nova.core.tool.util.BeanToMapUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 租户用户信息 前端控制器
 *
 * @author Uchihashiamu
 */
@RestController
@AllArgsConstructor
@RequestMapping("/tenantUser")
@Tag(name = "租户用户信息前端控制器")
@Slf4j
public class TenantUserController extends BaseController {
    @Resource
    TenantUserFeignService  tenantUserFeignService;

    @Operation(summary = "分页查询")
    @GetMapping(NovaCRUDMethodConstant.NOVA_WEB_PAGE)
    public R getPage(TenantUserQuery query, QueryContext queryContext){
        NovaUser novaUser = getNovaUser();
        query.setTenantId(novaUser.getTenantId());
        List<Object> list = Lists.newArrayList(query,queryContext);
        Map<String,Object> map = BeanToMapUtil.beanToMap(list);
        return tenantUserFeignService.getPage(map);
    }

    @Operation(summary = "详情")
    @GetMapping(NovaCRUDMethodConstant.NOVA_WEB_GETONE)
    public R getOne(TenantUserDTO tenantUserDTO){
        NovaUser novaUser = getNovaUser();
        tenantUserDTO.setTenantId(novaUser.getTenantId());
        return tenantUserFeignService.detail(tenantUserDTO);
    }

    @Operation(summary = "新增")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVE)
    public R save(@RequestBody TenantUserDTO tenantUserDTO){
        return tenantUserFeignService.save(tenantUserDTO);
    }

    @Operation(summary = "修改")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_UPDATE)
    public R update(@RequestBody TenantUserDTO tenantUserDTO){
        return tenantUserFeignService.update(tenantUserDTO);
    }

    @Operation(summary = "新增或者修改")
    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_SAVEORUPDATE)
    public R saveOrUpdate(@RequestBody TenantUserDTO tenantUserDTO){
        return tenantUserFeignService.saveOrUpdate(tenantUserDTO);
    }

    @PostMapping(NovaCRUDMethodConstant.NOVA_WEB_REMOVE)
    @Operation(summary = "逻辑删除")
    public R remove(@RequestParam String ids){
        return tenantUserFeignService.remove(ids);
    }

    @Operation(summary = "物理删除")
    @DeleteMapping(NovaCRUDMethodConstant.NOVA_WEB_DELETE)
    public R delete(@RequestParam String ids){
        return tenantUserFeignService.delete(ids);
    }
}
